package com.material.demo.activity;

import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.os.Bundle;
import android.util.Log;

import com.material.demo.lyric.LyricView;
import com.material.demo.lyric.ZrceParser;

import java.io.IOException;
import java.io.InputStream;

/**
 * Created by WenJackp on 2016/12/8.
 */
public class CustomBehaviorActivity extends DemoBaseActivity {
    private static final String REGEX = "<[0-9]{1,}>";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        setContentView(R.layout.activity_custom_behavior);

        try {
            InputStream stream = getResources().getAssets().open("23984.zrce");
            ZrceParser parser = new ZrceParser();
            parser.parser(stream);

            LyricView view = new LyricView(this);
            view.setBackgroundColor(Color.RED);
            view.setLyricParser(parser);
            setContentView(view);
            view.start();
        } catch (IOException e) {
            e.printStackTrace();
            Log.e("LrcParser","  "+ e.toString());
        }

    }


    /**
     * 获取Paint绘制字体的位置 可以获取宽高
     *
     * @param txt
     * @param fontSize
     * @param paint
     * @return
     */
    private Rect getAdaptTextFontSize(String txt, int fontSize, Paint paint) {
//        float oldTextSize = paint.getTextSize();
        Rect rect = new Rect();
//        paint.setTextSize((float) fontSize);
        paint.getTextBounds(txt, 0, txt.length(), rect);

//        while(this.width > 0 && this.width < rect.right + 20) {
//            fontSize -= 2;
//            paint.setTextSize((float)fontSize);
//            paint.getTextBounds(txt, 0, txt.length(), rect);
//        }
//        paint.setTextSize(oldTextSize);
        return rect;
    }
}
